#!/usr/bin/env jruby

require 'test/unit'
dir = File.dirname(__FILE__)
require File.join(dir, '..', '..', 'lib', 'monkey', 'range')

########################################

class TestRangeJoin < Test::Unit::TestCase
  NONE = 0...0
  ONE = 1..1
  MANY = 1..5
  
  def test_should_validate_arg
    assert_raise(TypeError) { MANY.join(123) }
    assert_nothing_thrown('empty string') { MANY.join('') }
    assert_nothing_thrown('nil') { MANY.join(nil) }
  end
  
  def test_should_return_string
    assert_kind_of String, NONE.join, 'none nil'
    assert_kind_of String, ONE.join,  'one nil'
    assert_kind_of String, MANY.join, 'many nil'
    sep = ', '
    assert_kind_of String, NONE.join(sep), 'none string'
    assert_kind_of String, ONE.join(sep),  'one string'
    assert_kind_of String, MANY.join(sep), 'many string'
  end
  
  def test_should_join_smashed
    assert_equal '', NONE.join
    assert_equal '1', ONE.join
    assert_equal "1#{$,}2#{$,}3#{$,}4#{$,}5", MANY.join
  end
  
  def test_should_join_with_separator
    sep = ', '
    assert_equal '', NONE.join(sep)
    assert_equal '1', ONE.join(sep)
    assert_equal '1, 2, 3, 4, 5', MANY.join(sep)
  end
end
